//
//  EditUserInfoVC.m
//  MovieDate
//
//  Created by yyta on 16/4/13.
//  Copyright © 2016年 MovieDate. All rights reserved.
//

#import "EditUserInfoVC.h"
#import "PhotosSettingView.h"
#import "AlbumImageModel.h"
#import "AlbumImageView.h"
#import "EditDataViewCell.h"
#import "UserMovieLabelVC.h"

@interface EditUserInfoVC () <PhotosSettingDelegate, UINavigationControllerDelegate, UIActionSheetDelegate, UIImagePickerControllerDelegate>
{
    PhotosSettingView *viewPics;
    
    NSMutableArray *pArrayLabel;
    NSMutableArray *pArrayLabelUUID;
    NSArray *pArrayPlaceholder;
}

@property (strong,nonatomic) AlbumImageView *selectImageView;

@property (strong, nonatomic) IBOutlet UIView *pViewHeader;
@property (weak, nonatomic) IBOutlet UITextView *pTxtSign;
@property (weak, nonatomic) IBOutlet UILabel *pLblNickName;
@property (weak, nonatomic) IBOutlet UILabel *pLblPhone;
@property (weak, nonatomic) IBOutlet UITextField *pTxtAge;

@end

@implementation EditUserInfoVC

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = NO;
}

- (void)initInfo
{
    [super initInfo];
    [self selAddLeftBackButton];
    [self selDefaultNavigationWithTitle:@"个人信息"];
    [self initTableViewHeader];
    self.automaticallyAdjustsScrollViewInsets = YES;
    [self selAddRightButton:@"完成" imageName:nil selector:@selector(btnRightAction:)];
    
    _pTxtSign.layer.borderWidth = 0.5;
    [_pTxtSign.layer setBorderColor:[UIColor colorWithRed:102/255.0f green:102/255.0f blue:102/255.0f alpha:1].CGColor];
    [_pTxtSign.layer setCornerRadius:5.0f];
    [_pTxtSign.layer setMasksToBounds:YES];
    
    [_pViewHeader setFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.width + 326)];
    [self.pTableView setTableHeaderView:_pViewHeader];
    
    pArrayLabel = [NSMutableArray arrayWithObjects:@"", @"", @"", @"", @"", @"", @"", nil];
    pArrayLabelUUID = [NSMutableArray arrayWithObjects:@"", @"", @"", @"", @"", @"", @"", nil];
    pArrayPlaceholder = [NSArray arrayWithObjects:@"选择你的星座", @"添加你喜欢的美食", @"添加你喜欢的电影", @"添加你喜欢的演员", @"添加你喜欢的导演", @"添加你喜欢的电影类型", @"添加你常去的电影院", nil];
    [self selShowData];

    User *user = [User defaultUser];
    self.pLblNickName.text      = [NSString stringWithFormat:@"%@", user.nickName];
    self.pTxtAge.placeholder    = [NSString stringWithFormat:@"%@",user.userAge];
    self.pLblPhone.text         = [NSString stringWithFormat:@"%@", user.phone];
    NSString *strSign = [NSString stringWithFormat:@"%@", user.signature];
    if (!strSign || [strSign rangeOfString:@"null"].length > 0 || strSign.length == 0) {
        self.pTxtSign.text  = @"这个人很懒,什么都没留下!";
    } else {
        self.pTxtSign.text  = strSign;
    }
}

- (void)selShowData
{
    User *user = [User defaultUser];
    for (MovieLabelModel *mlm in user.labels)
    {
        if ([mlm.type isEqualToString:@"1"] && ![mlm.name isEqualToString:@""]) {
            [pArrayLabel replaceObjectAtIndex:0 withObject:mlm];
            [pArrayLabelUUID replaceObjectAtIndex:0 withObject:mlm.uuid];
        } else if ([mlm.type isEqualToString:@"2"] && ![mlm.name isEqualToString:@""]) {
            id idData = [pArrayLabel objectAtIndex:1];
            if (![idData isKindOfClass:[NSArray class]]) {
                idData = nil;
                idData = [NSArray array];
            }
            NSMutableArray *array = [NSMutableArray arrayWithArray:idData];
            if (!array || ![array isKindOfClass:[NSArray class]]) {
                array = nil;
                array = [NSMutableArray array];
            }
            [array addObject:mlm];
            [pArrayLabel replaceObjectAtIndex:1 withObject:array];
            [pArrayLabelUUID replaceObjectAtIndex:1 withObject:array];
        } else if ([mlm.type isEqualToString:@"3"] && ![mlm.name isEqualToString:@""]) {
            id idData = [pArrayLabel objectAtIndex:2];
            if (![idData isKindOfClass:[NSArray class]]) {
                idData = nil;
                idData = [NSArray array];
            }
            NSMutableArray *array = [NSMutableArray arrayWithArray:idData];
            if (!array || ![array isKindOfClass:[NSArray class]]) {
                array = nil;
                array = [NSMutableArray array];
            }
            [array addObject:mlm];
            [pArrayLabel replaceObjectAtIndex:2 withObject:array];
            [pArrayLabelUUID replaceObjectAtIndex:2 withObject:array];
        } else if ([mlm.type isEqualToString:@"4"] && ![mlm.name isEqualToString:@""]) {
            id idData = [pArrayLabel objectAtIndex:3];
            if (![idData isKindOfClass:[NSArray class]]) {
                idData = nil;
                idData = [NSArray array];
            }
            NSMutableArray *array = [NSMutableArray arrayWithArray:idData];
            if (!array || ![array isKindOfClass:[NSArray class]]) {
                array = nil;
                array = [NSMutableArray array];
            }
            [array addObject:mlm];
            [pArrayLabel replaceObjectAtIndex:3 withObject:array];
            [pArrayLabelUUID replaceObjectAtIndex:3 withObject:array];
        } else if ([mlm.type isEqualToString:@"5"] && ![mlm.name isEqualToString:@""]) {
            id idData = [pArrayLabel objectAtIndex:4];
            if (![idData isKindOfClass:[NSArray class]]) {
                idData = nil;
                idData = [NSArray array];
            }
            NSMutableArray *array = [NSMutableArray arrayWithArray:idData];
            if (!array || ![array isKindOfClass:[NSArray class]]) {
                array = nil;
                array = [NSMutableArray array];
            }
            [array addObject:mlm];
            [pArrayLabel replaceObjectAtIndex:4 withObject:array];
            [pArrayLabelUUID replaceObjectAtIndex:4 withObject:array];
        } else if ([mlm.type isEqualToString:@"6"] && ![mlm.name isEqualToString:@""]) {
            id idData = [pArrayLabel objectAtIndex:5];
            if (![idData isKindOfClass:[NSArray class]]) {
                idData = nil;
                idData = [NSArray array];
            }
            NSMutableArray *array = [NSMutableArray arrayWithArray:idData];
            if (!array || ![array isKindOfClass:[NSArray class]]) {
                array = nil;
                array = [NSMutableArray array];
            }
            [array addObject:mlm];
            [pArrayLabel replaceObjectAtIndex:5 withObject:array];
            [pArrayLabelUUID replaceObjectAtIndex:5 withObject:array];
        } else if ([mlm.type isEqualToString:@"7"] && ![mlm.name isEqualToString:@""]) {
            id idData = [pArrayLabel objectAtIndex:6];
            if (![idData isKindOfClass:[NSArray class]]) {
                idData = nil;
                idData = [NSArray array];
            }
            NSMutableArray *array = [NSMutableArray arrayWithArray:idData];
            if (!array || ![array isKindOfClass:[NSArray class]]) {
                array = nil;
                array = [NSMutableArray array];
            }
            [array addObject:mlm];
            [pArrayLabel replaceObjectAtIndex:6 withObject:array];
            [pArrayLabelUUID replaceObjectAtIndex:6 withObject:array];
        }
    }
}

//点击完成按钮
- (void)btnRightAction:(UIButton *)btn
{
    User *user = [User defaultUser];
    if (self.pTxtAge.text.length == 0) {
        user.userAge = self.pTxtAge.placeholder;
    } else {
        user.userAge = self.pTxtAge.text;
    }
    if (![self.pTxtSign.text isEqualToString:@"这个人很懒,什么都没留下!"]) {
        user.signature = self.pTxtSign.text;
    } else {
        user.signature = @"";
    }
    
    NSString *identifierForVendor = [[UIDevice currentDevice].identifierForVendor UUIDString];
    [SVProgressHUD show];
    [TDNetwork upDataUserMessagePostUrl:updateUserMessageIP uid:[user.uid integerValue] token:identifierForVendor nickName:user.nickName userSex:user.userSex signature:user.signature userAge:user.userAge movieLabel:user.movieLabel oftenAddress:user.pStrLocationAddress loveMovie:@"" professional:@"" userSkill:@"" complete:^(BOOL succeed, NSString *ret, NSDictionary *dictionary) {
        [SVProgressHUD dismiss];
        if (succeed)
        {
            [SVProgressHUD show];
            NSMutableArray *array = [NSMutableArray array];
            for (MovieLabelModel *item in pArrayLabelUUID) {
                if ([item isKindOfClass:[MovieLabelModel class]]) {
                    [array addObject:item.uuid];
                } else {
                    if ([item isKindOfClass:[NSArray class]]) {
                        for (MovieLabelModel *j in (NSArray *)item) {
                            [array addObject:j.uuid];
                        }
                    } else {
                        NSString *strUUid = (NSString *)item;
                        if (strUUid.length > 0) {
                            [array addObject:strUUid];
                        }
                    }
                }
            }
            [TDNetwork updateUserLabel:updateMovieLabel_interface userLabels:array complete:^(BOOL succeed, NSString *ret, NSDictionary *dictionary) {
                [SVProgressHUD dismiss];
                if (succeed) {
                    [self.navigationController popViewControllerAnimated:YES];
                } else {
                }
            }];
        } else {
        }
    }];
}

- (void)initTableViewHeader
{
    viewPics.delegate = nil;
    [viewPics removeFromSuperview];
    viewPics = nil;
    viewPics = [[PhotosSettingView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.width)];
    viewPics.delegate = self;
    [self.pViewHeader addSubview:viewPics];
    
    User *user = [User defaultUser];
    __weak typeof(self) weakSelf = self;
    
    [TDNetwork getUserAlbumImagePostUrl:getAlbumImageIP uid:[user.uid integerValue] complete:^(BOOL succeed, NSString *ret, NSDictionary *dictionary) {
        if (succeed) {
            NSArray *arr  = [[dictionary valueForKey:@"res"] valueForKey:@"albumList"];
            for (int i = 0; i < arr.count; i++) {
                NSDictionary *dict = [arr objectAtIndex:i];
                if (dict && [dict isKindOfClass:[NSDictionary class]]) {
                    switch (i) {
                        case 0: {
                            [weakSelf selSetImageInfo:viewPics.pImg1 byDict:dict];
                        }
                            break;
                            
                        case 1: {
                            [weakSelf selSetImageInfo:viewPics.pImg2 byDict:dict];
                        }
                            break;
                            
                        case 2: {
                            [weakSelf selSetImageInfo:viewPics.pImg3 byDict:dict];
                        }
                            break;
                            
                        case 3: {
                            [weakSelf selSetImageInfo:viewPics.pImg4 byDict:dict];
                        }
                            break;
                            
                        case 4: {
                            [weakSelf selSetImageInfo:viewPics.pImg5 byDict:dict];
                        }
                            break;
                            
                        case 5: {
                            [weakSelf selSetImageInfo:viewPics.pImg6 byDict:dict];
                        }
                            break;
                    }
                }
            }
        }
    }];
}

- (void)selSetImageInfo:(AlbumImageView *)image byDict:(NSDictionary *)dict
{
    [image sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/api/common/file/imgGet?fid=%@", IP, [dict objectForKey:@"albumId"]]]];
    [image setContentMode:UIViewContentModeScaleToFill];
    image.albumId = [dict objectForKey:@"albumId"];
    image.albumContent = [dict objectForKey:@"albumContent"];
    image.albumTitle = [dict objectForKey:@"albumTitle"];
    image.uid = [dict objectForKey:@"uid"];
    image.uuid = [dict objectForKey:@"uuid"];
}


#pragma mark -PhotosSettingDelegate
//选择图片事件
-(void)selSelectImg:(AlbumImageView *)imageView {
    imageView.userInteractionEnabled = YES;
    self.selectImageView = imageView;
    //在这里呼出下方菜单按钮项
    UIActionSheet *myActionSheet = [[UIActionSheet alloc] initWithTitle:@"请上传您的真实照片" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"删除", @"打开照相机", @"从手机相册获取",nil];
    [myActionSheet showInView:self.view];
}

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    //呼出的菜单按钮点击后的响应
    if (buttonIndex == actionSheet.cancelButtonIndex) {
    }
    
    switch (buttonIndex)
    {
        case 0:  //删除图片
            if (_selectImageView.albumId.length > 0) {
                [self deleteImageWithNew:@""];
            }
            break;
            
        case 1:  //打开照相机拍照
            [self takePhoto];
            break;
            
        case 2:  //打开本地相册
            [self LocalPhoto];
            break;
    }
}

//删除图片
-(void)deleteImageWithNew:(NSString *)strJson
{
    [SVProgressHUD show];
    [TDNetwork deleteUserAlbumImagePostUrl:deleteAlbumImageIP albumId:[_selectImageView.albumId integerValue] complete:^(BOOL succeed, NSString *ret, NSDictionary *dictionary) {
        [SVProgressHUD dismiss];
        if (succeed) {
            
            if (strJson.length == 0) {
                _selectImageView.image = [UIImage imageNamed:@"bg"];
                _selectImageView.albumId = @"";
                _selectImageView.albumContent = @"";
                _selectImageView.albumTitle = @"";
                _selectImageView.uid = @"";
                _selectImageView.uuid = @"";
            } else {
                [TDNetwork settingUserAlbumImagePostUrl:settingAlbumImageIP albumJson:strJson complete:^(BOOL succeed, NSString *ret, NSDictionary *dictionary) {
                    if (succeed) {
                        if ([ret intValue] == 1) {
                            [self initTableViewHeader];
                        }
                    }
                }];
            }
        }
    }];
}

//开始拍照
-(void)takePhoto
{
    UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera;
    if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera])
    {
        UIImagePickerController *picker = [[UIImagePickerController alloc] init];
        picker.delegate = self;
        //设置拍照后的图片可被编辑
        picker.allowsEditing = YES;
        picker.sourceType = sourceType;
        [self presentViewController:picker animated:YES completion:^{}];
    }else{
        NSLog(@"模拟其中无法打开照相机,请在真机中使用");
    }
}

//打开本地相册
-(void)LocalPhoto
{
    NSLog(@"sdasd");
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    
    picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    picker.delegate = self;
    //设置选择后的图片可被编辑
    picker.allowsEditing = YES;
    [self presentViewController:picker animated:YES completion:^{}];
}

//当选择一张图片后进入这里
-(void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    NSString *type = [info objectForKey:UIImagePickerControllerMediaType];
    
    //当选择的类型是图片
    if ([type isEqualToString:@"public.image"])
    {
        //先把图片转成NSData
        UIImage* image = [info objectForKey:@"UIImagePickerControllerEditedImage"];
        NSData *data;
        if (UIImagePNGRepresentation(image) == nil)
        {
            data = UIImageJPEGRepresentation(image, 1.0);
        }
        else{
            data = UIImagePNGRepresentation(image);
        }
        
        self.selectImageView.image = image;
        //关闭相册界面
        [picker dismissViewControllerAnimated:YES completion:^{}];
        User *user= [User defaultUser];
        NSData *_data = UIImageJPEGRepresentation(image, 0.5f);
        
        NSString *encodedImageStr = [_data base64Encoding];
        [SVProgressHUD show];
        [TDNetwork uploadingUserPicImagePostUrl:uploadingPicImageIP imgName:[NSString stringWithFormat:@"%@.png",@"xx"] imgData:encodedImageStr title:@"相册图片" type:@"png" complete:^(BOOL succeed, NSString *ret, NSDictionary *dictionary){
            [SVProgressHUD dismiss];
            NSString *fid= [NSString stringWithFormat:@"%@", [[dictionary valueForKey:@"res"] valueForKey:@"fid"]];
            BOOL isAddPic = NO;
            if (viewPics.pImg1.albumId.length == 0) {
                isAddPic = YES;
            } else if (viewPics.pImg2.albumId.length == 0) {
                isAddPic = YES;
            } else if (viewPics.pImg3.albumId.length == 0) {
                isAddPic = YES;
            } else if (viewPics.pImg4.albumId.length == 0) {
                isAddPic = YES;
            } else if (viewPics.pImg5.albumId.length == 0) {
                isAddPic = YES;
            } else if (viewPics.pImg6.albumId.length == 0) {
                isAddPic = YES;
            }
            
            if (isAddPic) {
                [TDNetwork settingUserAlbumImagePostUrl:settingAlbumImageIP albumJson:[NSString stringWithFormat:@"[{\"albumId\":%@,\"uid\":%@,\"albumTitle\":\"%@\",\"albumContent\":\"%@\"}]", fid, user.uid, @"", [NSString stringWithFormat:@"%@", [NSDate date]]] complete:^(BOOL succeed, NSString *ret, NSDictionary *dictionary) {
                    if (succeed) {
                        if ([ret intValue] == 1) {
                            [self initTableViewHeader];
                        }
                    }
                }];
            } else {
                [self deleteImageWithNew:[NSString stringWithFormat:@"[{\"albumId\":%@,\"uid\":%@,\"albumTitle\":\"%@\",\"albumContent\":\"%@\"}]", fid, user.uid, @"", @""]];
            }
        }];
    }
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
    [picker dismissViewControllerAnimated:YES completion:^{}];
}


#pragma mark - UITableViewDataSource, UITableViewDelegate

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 7;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    EditDataViewCell *cell = (EditDataViewCell *)[tableView dequeueReusableCellWithIdentifier:@"idfEditUserInfoCell"];
    
    cell.contentTXF.layer.masksToBounds = YES;
    cell.contentTXF.layer.cornerRadius = 10;
    cell.contentTXF1.layer.masksToBounds = YES;
    cell.contentTXF1.layer.cornerRadius = 10;
    cell.contentTXF2.layer.masksToBounds = YES;
    cell.contentTXF2.layer.cornerRadius = 10;
    cell.contentTXF3.layer.masksToBounds = YES;
    cell.contentTXF3.layer.cornerRadius = 10;
    cell.contentTXF4.layer.masksToBounds = YES;
    cell.contentTXF4.layer.cornerRadius = 10;
    cell.contentTXF5.layer.masksToBounds = YES;
    cell.contentTXF5.layer.cornerRadius = 10;
    
    [cell.contentTXF1 setHidden:YES];
    [cell.contentTXF2 setHidden:YES];
    [cell.contentTXF3 setHidden:YES];
    [cell.contentTXF4 setHidden:YES];
    [cell.contentTXF5 setHidden:YES];

    switch (indexPath.row)
    {
        case 0:
        {
            cell.pLblTitle.text = @"星   座";
            MovieLabelModel *mlm = [pArrayLabel objectAtIndex:indexPath.row];
            if ([mlm isKindOfClass:[MovieLabelModel class]]) {
                cell.contentTXF.text = [NSString stringWithFormat:@"  %@      ", mlm.name];
            }
            if ([mlm isKindOfClass:[MovieLabelModel class]]) {
                cell.contentTXF.textColor = [UIColor colorWithRed:254.0/255 green:189.0/255 blue:1.0/255 alpha:1];
                cell.contentTXF.backgroundColor = [UIColor colorWithRed:255.0/255 green:250.0/255 blue:238.0/255 alpha:1];
            } else {
                cell.contentTXF.placeholder = [pArrayPlaceholder objectAtIndex:0];
            }
        }
            break;
            
        case 1:
        {
            cell.pLblTitle.text = @"美   食";
            id idData = [pArrayLabel objectAtIndex:indexPath.row];
            
            if ([idData isKindOfClass:[NSArray class]])
            {
                cell.contentTXF.textColor = [UIColor colorWithRed:254.0/255 green:144.0/255 blue:57.0/255 alpha:1];
                cell.contentTXF.backgroundColor = [UIColor colorWithRed:255.0/255 green:246.0/255 blue:239.0/255 alpha:1];
                cell.contentTXF1.textColor = [UIColor colorWithRed:254.0/255 green:144.0/255 blue:57.0/255 alpha:1];
                cell.contentTXF1.backgroundColor = [UIColor colorWithRed:255.0/255 green:246.0/255 blue:239.0/255 alpha:1];
                cell.contentTXF2.textColor = [UIColor colorWithRed:254.0/255 green:144.0/255 blue:57.0/255 alpha:1];
                cell.contentTXF2.backgroundColor = [UIColor colorWithRed:255.0/255 green:246.0/255 blue:239.0/255 alpha:1];
                cell.contentTXF3.textColor = [UIColor colorWithRed:254.0/255 green:144.0/255 blue:57.0/255 alpha:1];
                cell.contentTXF3.backgroundColor = [UIColor colorWithRed:255.0/255 green:246.0/255 blue:239.0/255 alpha:1];
                cell.contentTXF4.textColor = [UIColor colorWithRed:254.0/255 green:144.0/255 blue:57.0/255 alpha:1];
                cell.contentTXF4.backgroundColor = [UIColor colorWithRed:255.0/255 green:246.0/255 blue:239.0/255 alpha:1];
                cell.contentTXF5.textColor = [UIColor colorWithRed:254.0/255 green:144.0/255 blue:57.0/255 alpha:1];
                cell.contentTXF5.backgroundColor = [UIColor colorWithRed:255.0/255 green:246.0/255 blue:239.0/255 alpha:1];

                for (int i = 0; i < ((NSArray *)idData).count; i++) {
                    MovieLabelModel *model = [((NSArray *)idData) objectAtIndex:i];
                    if (i == 0) {
                        cell.contentTXF.placeholder = @"------";
                        cell.contentTXF.text = [NSString stringWithFormat:@"  %@  ", model.name];
                        [cell.contentTXF setHidden:NO];
                    } else if(i == 1) {
                        cell.contentTXF1.text = [NSString stringWithFormat:@"  %@  ", model.name];
                        [cell.contentTXF1 setHidden:NO];
                    } else if(i == 2) {
                        cell.contentTXF2.text = [NSString stringWithFormat:@"  %@  ", model.name];
                        [cell.contentTXF2 setHidden:NO];
                    } else if(i == 3) {
                        cell.contentTXF3.text = [NSString stringWithFormat:@"  %@  ", model.name];
                        [cell.contentTXF3 setHidden:NO];
                    } else if(i == 4) {
                        cell.contentTXF4.text = [NSString stringWithFormat:@"  %@  ", model.name];
                        [cell.contentTXF4 setHidden:NO];
                    } else if(i == 5) {
                        cell.contentTXF5.text = [NSString stringWithFormat:@"  %@  ", model.name];
                        [cell.contentTXF5 setHidden:NO];
                    }
                }
            } else {
                cell.contentTXF.placeholder = [pArrayPlaceholder objectAtIndex:1];
            }

        }
            break;
            
        case 2:
        {
            cell.pLblTitle.text = @"电   影";
            id idData = [pArrayLabel objectAtIndex:indexPath.row];
            
            if ([idData isKindOfClass:[NSArray class]])
            {
                cell.contentTXF.textColor = [UIColor colorWithRed:254.0/255 green:0.0/255 blue:2.0/255 alpha:1];
                cell.contentTXF.backgroundColor = [UIColor colorWithRed:255.0/255 green:238.0/255 blue:238.0/255 alpha:1];
                cell.contentTXF1.textColor = [UIColor colorWithRed:254.0/255 green:0.0/255 blue:2.0/255 alpha:1];
                cell.contentTXF1.backgroundColor = [UIColor colorWithRed:255.0/255 green:238.0/255 blue:238.0/255 alpha:1];
                cell.contentTXF2.textColor = [UIColor colorWithRed:254.0/255 green:0.0/255 blue:2.0/255 alpha:1];
                cell.contentTXF2.backgroundColor = [UIColor colorWithRed:255.0/255 green:238.0/255 blue:238.0/255 alpha:1];
                cell.contentTXF3.textColor = [UIColor colorWithRed:254.0/255 green:0.0/255 blue:2.0/255 alpha:1];
                cell.contentTXF3.backgroundColor = [UIColor colorWithRed:255.0/255 green:238.0/255 blue:238.0/255 alpha:1];
                cell.contentTXF4.textColor = [UIColor colorWithRed:254.0/255 green:0.0/255 blue:2.0/255 alpha:1];
                cell.contentTXF4.backgroundColor = [UIColor colorWithRed:255.0/255 green:238.0/255 blue:238.0/255 alpha:1];
                cell.contentTXF5.textColor = [UIColor colorWithRed:254.0/255 green:0.0/255 blue:2.0/255 alpha:1];
                cell.contentTXF5.backgroundColor = [UIColor colorWithRed:255.0/255 green:238.0/255 blue:238.0/255 alpha:1];
                
                for (int i = 0; i < ((NSArray *)idData).count; i++) {
                    MovieLabelModel *model = [((NSArray *)idData) objectAtIndex:i];
                    if (i == 0) {
                        cell.contentTXF.placeholder = @"------";
                        cell.contentTXF.text = [NSString stringWithFormat:@"  %@  ", model.name];
                        [cell.contentTXF setHidden:NO];
                    } else if(i == 1) {
                        cell.contentTXF1.text = [NSString stringWithFormat:@"  %@  ", model.name];
                        [cell.contentTXF1 setHidden:NO];
                    } else if(i == 2) {
                        cell.contentTXF2.text = [NSString stringWithFormat:@"  %@  ", model.name];
                        [cell.contentTXF2 setHidden:NO];
                    } else if(i == 3) {
                        cell.contentTXF3.text = [NSString stringWithFormat:@"  %@  ", model.name];
                        [cell.contentTXF3 setHidden:NO];
                    } else if(i == 4) {
                        cell.contentTXF4.text = [NSString stringWithFormat:@"  %@  ", model.name];
                        [cell.contentTXF4 setHidden:NO];
                    } else if(i == 5) {
                        cell.contentTXF5.text = [NSString stringWithFormat:@"  %@  ", model.name];
                        [cell.contentTXF5 setHidden:NO];
                    }
                }
            } else {
                cell.contentTXF.placeholder = [pArrayPlaceholder objectAtIndex:2];
            }
        }
            break;
        
        case 3:
        {
            cell.pLblTitle.text = @"演   员";
            id idData = [pArrayLabel objectAtIndex:indexPath.row];
            
            if ([idData isKindOfClass:[NSArray class]])
            {
                cell.contentTXF.textColor = [UIColor colorWithRed:195.0/255 green:17.0/255 blue:233.0/255 alpha:1];
                cell.contentTXF.backgroundColor = [UIColor colorWithRed:252.0/255 green:238.0/255 blue:255.0/255 alpha:1];
                cell.contentTXF1.textColor = [UIColor colorWithRed:195.0/255 green:17.0/255 blue:233.0/255 alpha:1];
                cell.contentTXF1.backgroundColor = [UIColor colorWithRed:252.0/255 green:238.0/255 blue:255.0/255 alpha:1];
                cell.contentTXF2.textColor = [UIColor colorWithRed:195.0/255 green:17.0/255 blue:233.0/255 alpha:1];
                cell.contentTXF2.backgroundColor = [UIColor colorWithRed:252.0/255 green:238.0/255 blue:255.0/255 alpha:1];
                cell.contentTXF3.textColor = [UIColor colorWithRed:195.0/255 green:17.0/255 blue:233.0/255 alpha:1];
                cell.contentTXF3.backgroundColor = [UIColor colorWithRed:252.0/255 green:238.0/255 blue:255.0/255 alpha:1];
                cell.contentTXF4.textColor = [UIColor colorWithRed:195.0/255 green:17.0/255 blue:233.0/255 alpha:1];
                cell.contentTXF4.backgroundColor = [UIColor colorWithRed:252.0/255 green:238.0/255 blue:255.0/255 alpha:1];
                cell.contentTXF5.textColor = [UIColor colorWithRed:195.0/255 green:17.0/255 blue:233.0/255 alpha:1];
                cell.contentTXF5.backgroundColor = [UIColor colorWithRed:252.0/255 green:238.0/255 blue:255.0/255 alpha:1];
                
                for (int i = 0; i < ((NSArray *)idData).count; i++) {
                    MovieLabelModel *model = [((NSArray *)idData) objectAtIndex:i];
                    if (i == 0) {
                        cell.contentTXF.placeholder = @"------";
                        cell.contentTXF.text = [NSString stringWithFormat:@"  %@  ", model.name];
                        [cell.contentTXF setHidden:NO];
                    } else if(i == 1) {
                        cell.contentTXF1.text = [NSString stringWithFormat:@"  %@  ", model.name];
                        [cell.contentTXF1 setHidden:NO];
                    } else if(i == 2) {
                        cell.contentTXF2.text = [NSString stringWithFormat:@"  %@  ", model.name];
                        [cell.contentTXF2 setHidden:NO];
                    } else if(i == 3) {
                        cell.contentTXF3.text = [NSString stringWithFormat:@"  %@  ", model.name];
                        [cell.contentTXF3 setHidden:NO];
                    } else if(i == 4) {
                        cell.contentTXF4.text = [NSString stringWithFormat:@"  %@  ", model.name];
                        [cell.contentTXF4 setHidden:NO];
                    } else if(i == 5) {
                        cell.contentTXF5.text = [NSString stringWithFormat:@"  %@  ", model.name];
                        [cell.contentTXF5 setHidden:NO];
                    }
                }
            } else {
                cell.contentTXF.placeholder = [pArrayPlaceholder objectAtIndex:3];
            }
        }
            break;
            
        case 4:
        {
            cell.pLblTitle.text = @"导   演";
            id idData = [pArrayLabel objectAtIndex:indexPath.row];
            
            if ([idData isKindOfClass:[NSArray class]])
            {
                cell.contentTXF.textColor = [UIColor colorWithRed:0.0/255 green:72.0/255 blue:255.0/255 alpha:1];
                cell.contentTXF.backgroundColor = [UIColor colorWithRed:239.0/255 green:243.0/255 blue:255.0/255 alpha:1];
                cell.contentTXF1.textColor = [UIColor colorWithRed:0.0/255 green:72.0/255 blue:255.0/255 alpha:1];
                cell.contentTXF1.backgroundColor = [UIColor colorWithRed:239.0/255 green:243.0/255 blue:255.0/255 alpha:1];
                cell.contentTXF2.textColor = [UIColor colorWithRed:0.0/255 green:72.0/255 blue:255.0/255 alpha:1];
                cell.contentTXF2.backgroundColor = [UIColor colorWithRed:239.0/255 green:243.0/255 blue:255.0/255 alpha:1];
                cell.contentTXF3.textColor = [UIColor colorWithRed:0.0/255 green:72.0/255 blue:255.0/255 alpha:1];
                cell.contentTXF3.backgroundColor = [UIColor colorWithRed:239.0/255 green:243.0/255 blue:255.0/255 alpha:1];
                cell.contentTXF4.textColor = [UIColor colorWithRed:0.0/255 green:72.0/255 blue:255.0/255 alpha:1];
                cell.contentTXF4.backgroundColor = [UIColor colorWithRed:239.0/255 green:243.0/255 blue:255.0/255 alpha:1];
                cell.contentTXF5.textColor = [UIColor colorWithRed:0.0/255 green:72.0/255 blue:255.0/255 alpha:1];
                cell.contentTXF5.backgroundColor = [UIColor colorWithRed:239.0/255 green:243.0/255 blue:255.0/255 alpha:1];
                
                for (int i = 0; i < ((NSArray *)idData).count; i++) {
                    MovieLabelModel *model = [((NSArray *)idData) objectAtIndex:i];
                    if (i == 0) {
                        cell.contentTXF.placeholder = @"------";
                        cell.contentTXF.text = [NSString stringWithFormat:@"  %@  ", model.name];
                        [cell.contentTXF setHidden:NO];
                    } else if(i == 1) {
                        cell.contentTXF1.text = [NSString stringWithFormat:@"  %@  ", model.name];
                        [cell.contentTXF1 setHidden:NO];
                    } else if(i == 2) {
                        cell.contentTXF2.text = [NSString stringWithFormat:@"  %@  ", model.name];
                        [cell.contentTXF2 setHidden:NO];
                    } else if(i == 3) {
                        cell.contentTXF3.text = [NSString stringWithFormat:@"  %@  ", model.name];
                        [cell.contentTXF3 setHidden:NO];
                    } else if(i == 4) {
                        cell.contentTXF4.text = [NSString stringWithFormat:@"  %@  ", model.name];
                        [cell.contentTXF4 setHidden:NO];
                    } else if(i == 5) {
                        cell.contentTXF5.text = [NSString stringWithFormat:@"  %@  ", model.name];
                        [cell.contentTXF5 setHidden:NO];
                    }
                }
            } else {
                cell.contentTXF.placeholder = [pArrayPlaceholder objectAtIndex:4];
            }
        }
            break;
            
        case 5:
        {
            cell.pLblTitle.text = @"电影类型";
            id idData = [pArrayLabel objectAtIndex:indexPath.row];
            
            if ([idData isKindOfClass:[NSArray class]])
            {
                cell.contentTXF.textColor = [UIColor colorWithRed:2.0/255 green:255.0/255 blue:196.0/255 alpha:1];
                cell.contentTXF.backgroundColor = [UIColor colorWithRed:239.0/255 green:255.0/255 blue:252.0/255 alpha:1];
                cell.contentTXF1.textColor = [UIColor colorWithRed:2.0/255 green:255.0/255 blue:196.0/255 alpha:1];
                cell.contentTXF1.backgroundColor = [UIColor colorWithRed:239.0/255 green:255.0/255 blue:252.0/255 alpha:1];
                cell.contentTXF2.textColor = [UIColor colorWithRed:2.0/255 green:255.0/255 blue:196.0/255 alpha:1];
                cell.contentTXF2.backgroundColor = [UIColor colorWithRed:239.0/255 green:255.0/255 blue:252.0/255 alpha:1];
                cell.contentTXF3.textColor = [UIColor colorWithRed:2.0/255 green:255.0/255 blue:196.0/255 alpha:1];
                cell.contentTXF3.backgroundColor = [UIColor colorWithRed:239.0/255 green:255.0/255 blue:252.0/255 alpha:1];
                cell.contentTXF4.textColor = [UIColor colorWithRed:2.0/255 green:255.0/255 blue:196.0/255 alpha:1];
                cell.contentTXF4.backgroundColor = [UIColor colorWithRed:239.0/255 green:255.0/255 blue:252.0/255 alpha:1];
                cell.contentTXF5.textColor = [UIColor colorWithRed:2.0/255 green:255.0/255 blue:196.0/255 alpha:1];
                cell.contentTXF5.backgroundColor = [UIColor colorWithRed:239.0/255 green:255.0/255 blue:252.0/255 alpha:1];
                
                for (int i = 0; i < ((NSArray *)idData).count; i++) {
                    MovieLabelModel *model = [((NSArray *)idData) objectAtIndex:i];
                    if (i == 0) {
                        cell.contentTXF.placeholder = @"------";
                        cell.contentTXF.text = [NSString stringWithFormat:@"  %@  ", model.name];
                        [cell.contentTXF setHidden:NO];
                    } else if(i == 1) {
                        cell.contentTXF1.text = [NSString stringWithFormat:@"  %@  ", model.name];
                        [cell.contentTXF1 setHidden:NO];
                    } else if(i == 2) {
                        cell.contentTXF2.text = [NSString stringWithFormat:@"  %@  ", model.name];
                        [cell.contentTXF2 setHidden:NO];
                    } else if(i == 3) {
                        cell.contentTXF3.text = [NSString stringWithFormat:@"  %@  ", model.name];
                        [cell.contentTXF3 setHidden:NO];
                    } else if(i == 4) {
                        cell.contentTXF4.text = [NSString stringWithFormat:@"  %@  ", model.name];
                        [cell.contentTXF4 setHidden:NO];
                    } else if(i == 5) {
                        cell.contentTXF5.text = [NSString stringWithFormat:@"  %@  ", model.name];
                        [cell.contentTXF5 setHidden:NO];
                    }
                }
            } else {
                cell.contentTXF.placeholder = [pArrayPlaceholder objectAtIndex:5];
            }
        }
            break;
            
        case 6:
        {
            cell.pLblTitle.text = @"常去影院";
            id idData = [pArrayLabel objectAtIndex:indexPath.row];
            
            if ([idData isKindOfClass:[NSArray class]])
            {
                cell.contentTXF.textColor = [UIColor colorWithRed:.0/255 green:255.0/255 blue:0.0/255 alpha:1];
                cell.contentTXF.backgroundColor = [UIColor colorWithRed:240.0/255 green:255.0/255 blue:200.0/255 alpha:1];
                cell.contentTXF1.textColor = [UIColor colorWithRed:.0/255 green:255.0/255 blue:0.0/255 alpha:1];
                cell.contentTXF1.backgroundColor = [UIColor colorWithRed:240.0/255 green:255.0/255 blue:200.0/255 alpha:1];
                cell.contentTXF2.textColor = [UIColor colorWithRed:.0/255 green:255.0/255 blue:0.0/255 alpha:1];
                cell.contentTXF2.backgroundColor = [UIColor colorWithRed:240.0/255 green:255.0/255 blue:200.0/255 alpha:1];
                cell.contentTXF3.textColor = [UIColor colorWithRed:.0/255 green:255.0/255 blue:0.0/255 alpha:1];
                cell.contentTXF3.backgroundColor = [UIColor colorWithRed:240.0/255 green:255.0/255 blue:200.0/255 alpha:1];
                cell.contentTXF4.textColor = [UIColor colorWithRed:.0/255 green:255.0/255 blue:0.0/255 alpha:1];
                cell.contentTXF4.backgroundColor = [UIColor colorWithRed:240.0/255 green:255.0/255 blue:200.0/255 alpha:1];
                cell.contentTXF5.textColor = [UIColor colorWithRed:.0/255 green:255.0/255 blue:0.0/255 alpha:1];
                cell.contentTXF5.backgroundColor = [UIColor colorWithRed:240.0/255 green:255.0/255 blue:200.0/255 alpha:1];
                
                for (int i = 0; i < ((NSArray *)idData).count; i++) {
                    MovieLabelModel *model = [((NSArray *)idData) objectAtIndex:i];
                    if (i == 0) {
                        cell.contentTXF.placeholder = @"------";
                        cell.contentTXF.text = [NSString stringWithFormat:@"  %@  ", model.name];
                        [cell.contentTXF setHidden:NO];
                    } else if(i == 1) {
                        cell.contentTXF1.text = [NSString stringWithFormat:@"  %@  ", model.name];
                        [cell.contentTXF1 setHidden:NO];
                    } else if(i == 2) {
                        cell.contentTXF2.text = [NSString stringWithFormat:@"  %@  ", model.name];
                        [cell.contentTXF2 setHidden:NO];
                    } else if(i == 3) {
                        cell.contentTXF3.text = [NSString stringWithFormat:@"  %@  ", model.name];
                        [cell.contentTXF3 setHidden:NO];
                    } else if(i == 4) {
                        cell.contentTXF4.text = [NSString stringWithFormat:@"  %@  ", model.name];
                        [cell.contentTXF4 setHidden:NO];
                    } else if(i == 5) {
                        cell.contentTXF5.text = [NSString stringWithFormat:@"  %@  ", model.name];
                        [cell.contentTXF5 setHidden:NO];
                    }
                }
            } else {
                cell.contentTXF.placeholder = [pArrayPlaceholder objectAtIndex:6];
            }
        }
            break;
    }
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    switch (indexPath.row)
    {
        case 0:
            return 44;
            
        case 1:
        case 2:
        case 3:
        case 4:
        case 5:
        case 6:
        {
            id idData = [pArrayLabel objectAtIndex:indexPath.row];
            if ([idData isKindOfClass:[NSArray class]])
            {
                if (((NSArray *)idData).count > 3) {
                    return 75;
                } else {
                    return 44;
                }
            }
        }
    }
    return 44;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    UIStoryboard *logStoyBoard = [UIStoryboard storyboardWithName:@"Login" bundle:nil];
    EditDataViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    UserMovieLabelVC  *userMovieLabelVC = [logStoyBoard instantiateViewControllerWithIdentifier:@"movieLabelVC"];
    [userMovieLabelVC returnText:^(NSString *showText, NSInteger index, NSString *uuid, NSArray *array) {
        UITextField *textFD = cell.contentTXF;
        if (showText) {
            textFD.text = showText;
            MovieLabelModel *mlm = [[MovieLabelModel alloc] init];
            mlm.name = showText;
            mlm.type = [NSString stringWithFormat:@"%ld", (long)index];
            mlm.uuid = uuid;
            
            NSMutableArray *arr = [NSMutableArray array];
            for (NSDictionary *dict in array) {
                MovieLabelModel *model = [[MovieLabelModel alloc] init];
                model.name = [dict objectForKey:@"name"];
                model.type = [dict objectForKey:@"type"];
                model.uuid = [dict objectForKey:@"uuid"];
                [arr addObject:model];
            }
            
            [pArrayLabel replaceObjectAtIndex:index-1 withObject:index==1?mlm:arr];
            [pArrayLabelUUID replaceObjectAtIndex:index-1 withObject:index==1?uuid:arr];
            [self.pTableView reloadData];
        }
    }];
    switch (indexPath.row) {
        case 0:
            userMovieLabelVC.pNavTitle = @"星座";
            [self.navigationController pushViewController:userMovieLabelVC animated:YES];
            break;
        case 1:
            
            userMovieLabelVC.pNavTitle = @"美食";
            [self.navigationController pushViewController:userMovieLabelVC animated:YES];
            break;
        case 2:
            userMovieLabelVC.pNavTitle = @"电影";
            [self.navigationController pushViewController:userMovieLabelVC animated:YES];
            break;
        case 3:
            userMovieLabelVC.pNavTitle = @"演员";
            [self.navigationController pushViewController:userMovieLabelVC animated:YES];
            
            break;
        case 4:
            userMovieLabelVC.pNavTitle = @"导演";
            [self.navigationController pushViewController:userMovieLabelVC animated:YES];
            
            break;
        case 5:
            userMovieLabelVC.pNavTitle = @"电影类型";
            [self.navigationController pushViewController:userMovieLabelVC animated:YES];
            
            break;
        case 6:
            userMovieLabelVC.pNavTitle = @"常去影院";
            [self.navigationController pushViewController:userMovieLabelVC animated:YES];
            break;
    }
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
